-- track
-- created by panyl
-- 标记一个怪物位置，击杀额外获得金钱

return {
    apply = function(prop, baseValue)
        return tonumber(prop[3]);
    end,

    -- 攻击时触发
    trigger = function(who, prop, arg)
        -- arg是怪物，为击杀触发，否则为生成触发
        if arg and arg.type == OBJECT_TYPE_MONSTER then
            -- 奖励探索点
            local bonus = { 2, "search_point", prop[3], };
            BonusM.doBonus(bonus, "track");

        else
            -- 副本、boss、神龙夹层都忽略
            local layer = DungeonM.currentLayer();
            local dungeonId = DungeonM.getDungeonId();
            if DungeonInstanceM.isInInstance() or
                DungeonBossM.isBossLayer(dungeonId, layer) or
                UnrealDungeonM.isInUnreal() then
                return;
            end

            local grids = CombatM.filterByType(DungeonM.getCurrentDungeon(), GRID_TYPE_MONSTER);

            local ret = {};
            for _, grid in pairs(grids) do
                if not grid:isOpened() and grid.monster and not grid.monster:isBoss() and not grid.monster:query("dragon") then
                    table.insert(ret, grid);
                end
            end

            grids = ret;

            if #grids <= 0 then
                return;
            end

            local rand = DungeonM.getRandSeed("track") % #grids;

            local grid = grids[rand + 1];

            if not grid.monster:query("dragon") then
                -- 不是神龙许愿标记过的
                grid.monster.dbase:set("track", true);
            end
        end

        -- 触发特技发动事件
        EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        return true;
    end,

    record = function(target, prop, path)
        local v = target.dbase:queryTemp("prop", path, {});
        table.insert(v, prop);
        target.dbase:setTemp("prop", path, v);

        -- DungeonServiceM.showMonsterBounty();
        return true;
    end
};
